/*
 * drv_encoder.h
 *
 *  Created on: 01/04/2014
 *      Author: f98877a
 */

#ifndef DRV_ENCODER_H_
#define DRV_ENCODER_H_


//*****************************************************************************
//
// Defines for the hardware resources used by the pushbuttons.
//
// The switches are on the following ports/pins:
//
// PF4 - Left Button
// PF0 - Right Button
//
// The switches tie the GPIO to ground, so the GPIOs need to be configured
// with pull-ups, and a value of 0 means the switch is pressed.
//
//*****************************************************************************
#define ENCODERS_GPIO_PERIPH     SYSCTL_PERIPH_GPIOE
#define ENCODERS_GPIO_BASE       GPIO_PORTE_BASE
#define ENCODERS_GPIO_INT        INT_GPIOE

#define NUM_ENCODERS             2
#define LEFT_ENCODER             GPIO_PIN_4
#define RIGHT_ENCODER            GPIO_PIN_5

#define ALL_ENCODERS             (LEFT_ENCODER | RIGHT_ENCODER)

#define LEFT_ENC         	 	16
#define RIGHT_ENC         	 	32
#define BOTH_ENC         	 	48
#define NO_ENC             	 	255

//*****************************************************************************
//
// Useful macros for detecting button events.
//
//*****************************************************************************
#define ENCODER_PRESSED(encoder, encoders, changed)                              \
        (((encoder) & (changed)) && ((encoder) & (encoders)))

#define ENCODER_RELEASED(encoder, encoders, changed)                             \
        (((encoder) & (changed)) && !((encoder) & (encoders)))

//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif

//*****************************************************************************
//
// Functions exported from buttons.c
//
//*****************************************************************************

extern unsigned char EncoderPoll(unsigned char *pucDelta,
                                 unsigned char *pucRaw);

//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif

//*****************************************************************************
//
// Prototypes for the globals exported by this driver.
//
//*****************************************************************************


#endif /* DRV_ENCODER_H_ */
